﻿@using DotNetDream.Common
@using DotNetDream.WebMetroEngine.Mvc.Models
@model DotNetDream.WebMetroEngine.Mvc.Models.DomainModules
@using (var db = new DotNetDream.WebMetroEngine.Mvc.Repository.ModuleRepository())
{
    //Find filtered Modules for selected Domain
    var modules = db.GetDomainModule(Model.DomainId, Model.ModuleNameFilter);
    Model.Modules = modules.Modules;

    //Build each Module tile UI
    foreach (var module in Model.Modules)
    {
        //Find full tile header
        var fullTile = module.Tiles.FirstOrDefault(t => t.Type.Name.ToLower().Equals("full"));
        string header = (fullTile != null) ? fullTile.Header : string.Empty;

        var previewTile = module.Tiles.Where(t => t.Type.Name.ToLower().Equals("preview")).FirstOrDefault();
        if (previewTile != null)
        {
    <div class="wme-layout-sidebar-tile">
        <div class="title-bar wme-button wme-theme" wme-data-fullheader="@header" wme-data-moduleid="@module.Id">
            <div id="btnTileConfig" class="wme-button wme-white-icon-small wme-icon-small-settings float-right">
            </div>
            <div style="padding: 2px 10px 0 0; font-weight: bold" class="float-right">
                @previewTile.Header.Shorten(20)
            </div>
        </div>
        @{
            //Default view
            string viewName = "_wmeDefaultPreview";
            //Custom view found
            if (!string.IsNullOrEmpty(previewTile.PartialView) && Benecura.Interfaces.WebMetro.Controllers.HomeController.ViewExists(previewTile.PartialView, "Shared"))
            {
                viewName = previewTile.PartialView;

            }
            //Render the view
            Html.RenderPartial(viewName, previewTile);
        }
    </div>
        }
        else
        {
    <div class="wme-view-notfound">
        @{Html.RenderPartial("_wmeNotFound", new Tile { PartialView = "Preview Tile" });}
    </div>
        }

    }
}
